package com.monkey.luffer.springboot.demo.basis.thread;

import com.google.common.base.Stopwatch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

/**
 * @Author: dengkaibing
 * @Description:
 * @Date: 2020/12/18 17:14
 * @company 甜橙金融
 * @Version: 1.0
 */
@Slf4j
public class ThreadTest {
    public static void main(String[] args) {
        testSpeed1();
        testSpeed2();
    }

    public static void testSpeed1() {
        final Stopwatch stopwatch = Stopwatch.createStarted();
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < 100000; i++) {
            list.add(i);
        }
        long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
        log.info("耗时：{}毫秒", elapsed);
    }

    public static void testSpeed2() {
        final Stopwatch stopwatch = Stopwatch.createStarted();
        TaskExecutors.executeTask(() -> {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < 5000; i++) {
                list.add(i);
            }
        });
        TaskExecutors.executeTask(() -> {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < 5000; i++) {
                list.add(i);
            }
        });
        long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
        log.info("耗时：{}毫秒", elapsed);
    }

    public void asyncTask(){
        AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
    }



}
